<template>
	<view>
	 <view>
		 <input type="text" placeholder="请输入手机号" v-model="codeData.account"/>
	 </view>
	 <view>
		 <input type="text" placeholder="验证码" v-model="phoneData.code" />
		 <button size="mini" @click="sendCode">获取验证码</button>
	 </view>
	 <view>
		 <button type="primary" :disabled="phoneData.code.length!=4"  @click="login">登录</button>
	 </view>
	</view>
</template>

<script setup>
	// 发送验证码接口
	 import {SendCode,LoginSMS} from '../../api/index.js'
	 import {ref} from 'vue'
	 // 发送验证码数据
	 const codeData = ref({
	"mobileArea":"+86",
	"account":"",
	"type":2
	})
	const phoneData = ref({
"mobileArea":"+86",
"mobile":codeData.value.account,
"code":"",
"sourceCode":601,
"callback":"https://m.xgimi.com/pages/user/user"
})
	// 发送验证码
	 function sendCode(){
		 SendCode(codeData.value)
		 .then(res=>{
			 console.log(res,"res");
			 uni.showToast({
			 	title:"验证码发送成功"
			 })
		 })
		 .catch(err=>{
			 console.log(err,"err");
		 })
	 }
	 function login(){
		 // 更新mobile值
		 LoginSMS({...phoneData.value,mobile:codeData.value.account})
		// 发送请求
		 .then(res=>{
			 if(res.code==200){
				 // 存储token
				 uni.setStorageSync("token",res.data.passToken)
				 // 返回
				 uni.navigateBack();
			 }
			
		 })
	 }
</script>

<style>

</style>
